/**
 * Created by Administrator on 2016-12-15.
 */


var http = require('http'),
    op = {
        hostname: '127.0.0.1',
        port: 8087,
        method: 'GET',
        path: 'http://www.baidu.com',
        headers: {
            host: 'www.baidu.com'
        }
    };
var iconv = require('iconv-lite');

var req = http.request(op, function (res) {
   // res.setEncoding('utf8')
    var chunks = []
    res.on('data', function (chunk) {
        chunks.push(chunk);
    });

    res.on('end', function () {
        var buf = Buffer.concat(chunks);
        var str = iconv.decode(buf, 'gbk');
        console.log('BODY:', str);
        console.log(http.globalAgent);
    });
});
req.on('error', function (e) {
    console.log('Error got: ' + e.message);
});
req.end();